<template>
	<view class="news_item">
		<view class="header">
			<view class="header-icon">
				<image src="../../static/icon/back.png" style="width: 40rpx;height: 40rpx;" @click="back"></image>
			</view>
			<view class="newsTitle">
				{{article_info.title}}
			</view>
		</view>
		<view class="content">
			
		<view class="info">
			<text>发表时间：{{article_info.gmtCreate }}</text>
			<text>浏览：{{article_info.heat}}</text>
		</view>
		<view class="imgContent">
			<view class="tit" v-html="article_content" />
		</view>
		</view>
		<!-- 回到顶部 -->
		<view class="wrap">
			<u-back-top :scroll-top="scrollTop"></u-back-top>
		</view>
	</view>
</template>

<script>
	export default {
		//过滤时间
		filters: {
			formatDate(date) {
				const nDate = new Date(date)
				const year = nDate.getFullYear()
				const month = nDate.getMonth().toString().padStart(2, 0)
				const day = nDate.getDate().toString().padStart(2, 0)
				return year + '-' + month + '-' + day
			}
		},
		data() {
			return {
				id: 0,
				serviceList: [],
				// 回到顶部样式
				scrollTop: 0,
				mode: "square",
				iconStyle: {
					fontSize: "32rpx",
					color: "#2979ff",
				},
				article_info: {},
				article_content: ''

			}
		},
		onLoad(options) {
			this.id = options.id
			this.getDetailList()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			//获取文章详情
			getDetailList() {
				uni.showLoading({
					title: "正在加载",
				});
				const that = this
				that.$api.request('article', 'detail', {
					articleId: that.id,
				}).then(res => {
					uni.hideLoading();
					that.article_info = res.data
					if (that.article_info.content) {
						that.article_content = that.article_info.content.replace(/\<img/gi,
							'<img style="max-width:100%;height:auto;padding:20rpx !important" ');
					}
				})
			},
			// 返回
			back() {
				const pages = getCurrentPages()
				if (pages && pages.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					history.go(-1)
				}
			}
		}
	}
</script>

<style lang="scss">
	.imgContent {
		padding: 0 30rpx;

		.tit {
			line-height: 1.7;
			margin-bottom: 30rpx;
		}
	}

	.news_item {
		.header {
			width: 100%;
			display: flex;
			padding: 50px 0 10px 0;
			position: fixed;
			background-color: #fff;
			.header-icon {
				padding: 20rpx 20rpx;
			}
		
			.newsTitle {
				padding-top: 18rpx;
				font-size: 35rpx;
				font-weight: bolder;
				display: flex;
				justify-content: center;
				flex-wrap: wrap;
				width: 80%;
			}
		}
		.content{
			height: 100%;
			padding-top: 110px;
		}
		.info {
			font-size: 20rpx;
			justify-content: space-between;
			display: flex;
			padding: 20rpx 30rpx 0;
			color: #999999;
		}
	}
</style>
